/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.Random;

/**
 * <p>Project: jse2204 - Arr4
 * <p>Powered by webrx On 2022-09-06 11:40:23
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Arr4 {
    public static void main(String[] args) {
        //01 声明数组
        int[] nums = new int[10];

        //02 数组元素赋值
        Random rand = new Random();
        for (int i = 0; i < nums.length; i++) nums[i] = rand.nextInt(1, 101);

        //03 排序前输出，直接使用Arrays.toString(nums);
        System.out.println("排序前：" + Arrays.toString(nums));

        //04排序算法（冒泡排序）
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length - 1; j++) {
                if (nums[j] < nums[j + 1]) {  // > 换为升序  < 换为降序
                    int a = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = a;
                }
            }
        }

        //05 排序输出
        System.out.println("排升序后：" + Arrays.toString(nums));

        //04排序算法（冒泡排序）
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length - 1; j++) {
                if (nums[j] > nums[j + 1]) {  // > 换为升序  < 换为降序
                    int a = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = a;
                }
            }
        }
        //05 排序输出
        System.out.println("排降序后：" + Arrays.toString(nums));

    }
}
